package com.leetcode.Offer;

import java.util.ArrayList;

public class JZ57_II_2 {
    public int[][] findContinuousSequence(int target) {
        int start = 1, end = 1, sum = 0;
        ArrayList<int[]> list = new ArrayList<>();
        while (start <= target / 2) {
            sum = (start + end) * (end - start + 1) / 2;
            if (sum < target) {
                end++;
            }
            if (sum > target) {
                start++;
            }
            if (sum == target) {
                int[] tmp = new int[end - start + 1];
                int index = 0;
                for (int i = start; i <= end; i++) {
                    tmp[index++] = start;
                }
                list.add(tmp);
                start++;
                end = start;
            }
        }
        return list.toArray(new int[list.size()][]);
    }
}
